<?php
class Application_Model_Factory_Mapper_DbTable implements Application_Model_Factory_MapperInterface
{
	/**
	 * 
	 * @var Application_Model_Factory_DomainInterface
	 */
	protected $_domainFactory;
	/**
	 * 
	 * @var Application_Model_Factory_DbTableInterface
	 */
	protected $_dbTableFactory;
	/**
	 * 
	 * @throws LogicException 
	 * @return Application_Model_MapperAbstract
	 */
	public function get ($type)
	{
		$className = 'Application_Model_Mapper_' . ucfirst($type);
		if (! class_exists($className)) {
			throw new LogicException(
				__METHOD__ . ', Cannot find classname ' . $className
			);
		}
		$mapperInstance = new $className();
		// check for domainFactory instance
		if (is_null($this->_domainFactory)) {
			throw new LogicException(
				__METHOD__ . ', Cannot create mapper instances if domainFactory is not set.'
			);
		}
		// check for dbTableFactory instance
		if (is_null($this->_dbTableFactory)) {
			throw new LogicException(
				__METHOD__ . ', Cannot create mapper instances if dbTableFactory is not set.'
			);
		}
		// inject domain/dbTable factories
		$mapperInstance->setDomainFactory($this->_domainFactory);
		$mapperInstance->setDbTableFactory($this->_dbTableFactory);
		return $mapperInstance;
	}
	/**
	 * 
	 * @param Application_Model_Factory_DomainInterface $domainFactory
	 */
	public function setDomainFactory (Application_Model_Factory_DomainInterface $domainFactory)
	{
		$this->_domainFactory = $domainFactory;
	}
	/**
	 * 
	 * @param Application_Model_Factory_DbTableInterface $dbTableFactory
	 */
	public function setDbTableFactory (Application_Model_Factory_DbTableInterface $dbTableFactory)
	{
		$this->_dbTableFactory = $dbTableFactory;
	}
}